<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default {
  // name: 'HomeView',
  // components: {
  //   HelloWorld
  // },

  data(){
    return {
      studentList: [],      // 当前页的所有学生信息集合
      page:1,               // 当前页
      pageSize:5,           // 每页大小
      total:100,            // 总记录数
    }
  },
  created() {
    //分页查询
    this.findByPage(this.page,this.pageSize)
  },

  methods:{
    //查询学生信息
    findStudents(){
      this.$axios.get('/student/list.do')
          .then(res => {
            console.log("数据：",res.data)
            this.studentList = res.data
          })
    },

    //分页查询
    findByPage(page,pageSize){
      this.$axios.get(`/student/findByPage.do?page=${page}&pageSize=${pageSize}`).then(res => {
        console.log("分页数据：",res)
        this.studentList = res.data.rows
        this.total = res.data.total
      })
    },

    handleEdit(index, row) {
      console.log(index, row);
    },

    handleDelete(index, row) {
      console.log(index, row);
    },

    //每页大小改变时事件
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.findByPage(this.page,this.pageSize)
    },

    // 当前页改变时事件
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page = val;
      this.findByPage(this.page,this.pageSize)
    }
  }
}
</script>